# modCalculator.py
# Ben Terris 12/3/07
# translation of Calculator.java from Steve Varga

from modCalculatable import Calculatable
from modCalculatablePolynomial import CalculatablePolynomial
from modStack import Stack

class Calculator(object):
    
    def __init__(self):
        self._opStack = Stack();

    def add(self):
        second, first = self._opStack.pop2()
        result = first + second

        self._opStack.push(result)
        return result

    def subtract(self):
        second, first = self._opStack.pop2()
        result = first - second

        self._opStack.push(result)
        return result

    def multiply(self):
        second, first = self._opStack.pop2()
        result = first * second

        self._opStack.push(result)
        return result

    def divide(self):
        second, first = self._opStack.pop2()
        result = first / second

        self._opStack.push(result)
        return result

    def square(self):
        first = self._opStack.pop()
        result = first.square()
        self._opStack.push(result)
        return result


    

    
        
    

   

if __name__ == '__main__':
    # run a battery of unit tests to ensure correct functionality
   

        
    def unittests():
        '''
        nothing
        '''

    from doctest import testmod
    testmod(verbose=True)
